<?php

namespace app\common\model;

use app\admin\model\Admin;
use think\Model;

/**
 * 学校
 */
class School extends Model
{

    protected $name = 'school';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'created_at';
    protected $updateTime = false;

    public function getLogoAttr($value)
    {
        if (!strstr($value, 'http') && strstr($value, '/uploads')) {
            $value = config('app_url') . $value;
        }
        return $value;
    }

    public function classes()
    {
        return $this->hasMany(Classes::class);
    }

    public function student()
    {
        return $this->hasMany(Student::class);
    }

    public function teacher()
    {
        return $this->hasMany(Teacher::class);
    }

    const NORMAL = 'normal';
    const HIDDEN = 'hidden';

    public static function getAllChildrenIds($ids)
    {
        static $output = [];
        $row = self::where('pid', 'in', $ids)->field('id')->select();
        if (!empty($row)){
            $row = collection($row)->toArray();
            $child_ids = array_column($row, 'id');
            $output = array_merge($output, $child_ids);
            static::getAllChildrenIds($child_ids);
        }
        return $output;
    }



}
